package org.study.bookmanagerclientbyswing.api;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import org.study.bookmanagerclientbyswing.io.request.PageReq;
import org.study.bookmanagerclientbyswing.io.response.RestBean;
import reactor.core.publisher.Mono;

@Component
public class ReservationApi {

    @Resource
    private WebClient webClient;

    private String baseUrl = "v1/reservation";

    public RestBean addReservation(int bookId) {
        return webClient.post()
                .uri(baseUrl+"/{bookId}", bookId)
                .retrieve()
                .bodyToMono(RestBean.class).block();
    }

    public RestBean deleteReservation(int Id) {
        return webClient.delete()
                .uri(baseUrl+"/{Id}", Id)
                .retrieve()
                .bodyToMono(RestBean.class).block();
    }

    public RestBean getReservations(PageReq pageReq) {
        return webClient.post()
                .uri(baseUrl+"/list")
                .bodyValue(pageReq)
                .retrieve()
                .bodyToMono(RestBean.class).block();
    }
}
